#include "E_Calender.h"


E_Calender::E_Calender(void)
{
}


E_Calender::~E_Calender(void)
{
}



//copy constructor - uses the base-calender copy-CTOR automaticly

//"=" operator - as above


bool E_Calender::addMeeting(int dayNum, float startTime, float endTime, string& subject,const vector<string> &people){
	if (legalTimeFormat(startTime) &&
		legalTimeFormat(endTime) &&
		legalDay(dayNum) && 
		(startTime<=endTime)){

		E_Meeting* m = new E_Meeting(startTime,endTime,subject);
		for(unsigned int i=0; i< people.size() ; i++){
			m->addPerson(people[i]);
		}

		bool flag = this->days[dayNum]->addMeeting(*m);

		if (!flag){
			delete(m);
		}

		return flag;

	} else {
		return false;
	}
}

	bool E_Calender::copyMeeting(const Meeting& oldm, int newDay, float newTime){
		if (legalDay(newDay) && legalTimeFormat(newTime) &&
			(newTime + oldm.getTimeEnd()-oldm.getTimeStart()) <= 24 ){

			if (oldm.whoAmI()==BASE)
				return false; //this protection isnt for our program - because E_Calender ALWAYS returns to the user- an E_Meeting.
								// this is future proofing against wrong mix use of a user.

			const E_Meeting oldEm = *(const E_Meeting *) &oldm;
			E_Meeting * m = new E_Meeting(oldEm);
			if (m == NULL) return false;

			m->setTimeStart(newTime);
			m->setTimeEnd(newTime + oldm.getTimeEnd()-oldm.getTimeStart());
			
			bool flag = days[newDay]->addMeeting(*m);
			if (!flag)
				delete(m);
			return flag;

		} else {
			return false;
		}

	}
